package cn.cs.service.impl;

import cn.cs.client.AgentSettlementDetailedClient;
import cn.cs.client.CsPersonClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.CsPerson;
import cn.cs.pojo.SettlementDetailed;
import cn.cs.service.SettlementDetailedService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class SettlementDetailedServiceImpl implements SettlementDetailedService {

    @Resource
    private AgentSettlementDetailedClient settlementDetailedClient;

    @Resource
    private CsPersonClient personClient;

    public Map<String, String> getSettlementDetailedById(String id) throws Exception {
        return settlementDetailedClient.getSettlementDetailedById(id);
    }

    public List<SettlementDetailed> getSettlementDetailedListByMap(Map<String, Object> param) throws Exception {
        return settlementDetailedClient.getSettlementDetailedListByMap(param);
    }

    public Integer getSettlementDetailedCountByMap(Map<String, Object> param) throws Exception {
        return settlementDetailedClient.getSettlementDetailedCountByMap(param);
    }

    public Integer addSettlementDetailed(SettlementDetailed settlementDetailed) throws Exception {
        return settlementDetailedClient.addSettlementDetailed(settlementDetailed);
    }

    public Integer modifySettlementDetailed(SettlementDetailed settlementDetailed) throws Exception {
        return settlementDetailedClient.modifySettlementDetailed(settlementDetailed);
    }

    public Integer deleteSettlementDetailedById(String id) throws Exception {
        return settlementDetailedClient.deleteSettlementDetailedById(id);
    }

    public Page<SettlementDetailed> querySettlementDetailedPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = settlementDetailedClient.getSettlementDetailedCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<SettlementDetailed> settlementDetailedList = settlementDetailedClient.getSettlementDetailedListByMap(param);
        for(SettlementDetailed a:settlementDetailedList){
            String personId = a.getPersonId();
            CsPerson person = personClient.findPersonById(personId);
            a.setPerson_name(person.getPersonName());
        }
        page.setRows(settlementDetailedList);
        return page;
    }

}
